from PySide2.QtCore import *
ERROR = 0
WARNING = 1
INFO =2
DEBUG = 3 

import time

class Log_signal(QObject):
    write_file = Signal(str)
    write_db = Signal(dict)
class Logger():
    def __init__(self) -> None:
        self.signal = Log_signal()

    def log_app(self,message:str,level:int = DEBUG):
        current_time = time.localtime()
        fmt_time = time.strftime('%Y-%m-%d %H:%M:%S',current_time)
        msg = f'{fmt_time} [{level}] {message}'
        print(msg)
        self.signal.write_file.emit(msg)

    def log_db(self,data:dict):
        self.signal.write_db.emit(data)